<?php

class System_UMS_CSVAdapter implements System_UMS_IUMSAdapter 
{

	//private $config;
	private $cvsPath;
	
	private $cvsDelimiter = "|";

	/** set configuration for the adapted, e.g. data base connection or CSV file name */
	public function __construct($config=null)
	{
		if ($config != null)
			$this->setConfig($config);
	}
	
	/** set configuration for the adapted, e.g. data base connection or CSV file name */
	public function setConfig($config)
	{
		$this->cvsPath = $config;		
	}
	
	public function userAdd($user)
	{
		$userFile = fopen ($this->cvsPath,"a" );
	    fputcsv($userFile, $this->serializeUser($user), $this->cvsDelimiter);
		fclose($userFile);		
	}
	
	private function readUsers()
	{
		
	}
	
	
	/**
	 * Converts a user object into an array of strings
	 * @param User $user
	 * @return array
	 */
	private function serializeUser($user)
	{
		$record = array();
		array_push($record, $user->getName());
		array_push($record, $user->getPassword());
		array_push($record, $user->getAge());
		array_push($record, $user->getEmail());
		return $record;
	}
	
	public function userDel($user)
	{
	}
	
	public function userMod($user)
	{
	}
	
	public function userGet($id)
	{
	}
}